﻿mini.parse();
var form = new mini.Form("form1");
var action;
function SaveData() {
	var o = form.getData();
	var json = mini.encode([o]);
	form.validate();
	if (form.isValid() == false) return;
	if (o.value1 <= 0) {
		mini.alert("充值金额不能小于0！");
		return;
	}
	if (action == "edit") {
		$.ajax({
			url: "../Service/SystemManageHandler.ashx?action=ModifyOrder",
			data: { data: json },
			type: 'POST',
			success: function(text) {
				CloseWindow("save");
			},
			error: function(jqXHR, textStatus, errorThrown) {
				alert(jqXHR.responseText);
			}
		});
	}
	else {
		$.ajax({
			url: "../Service/SystemManageHandler.ashx?action=AddOrder",
			data: { data: json },
			type: 'POST',
			success: function(text) {
				CloseWindow("save");
			},
			error: function(jqXHR, textStatus, errorThrown) {
				alert(jqXHR.responseText);
			}
		});
	}
}

////////////////////
//标准方法接口定义
function SetData(data) {
	data = mini.clone(data);
	if (data.action == "edit") {
		action = data.action;
		//跨页面传递的数据对象，克隆后才可以安全使用
		$.ajax({
			url: "../service/SystemManageHandler.ashx?action=GetOrderInfo&OrderId=" + data.OrderId,
			cache: false,
			success: function(text) {
				var o = mini.decode(text);
				form.setData(o);
				form.setChanged(false);
			}
		});
	}
}

function GetData() {
	var o = form.getData();
	return o;
}

function onMobileChanged(e) {
	if (e.value) {
		$.ajax({
			url: "../service/SystemManageHandler.ashx?action=GetMobileInfo&MobileCode=" + e.value,
			success: function(text) {
				$("#PhoneCallsAttribution").text(text);
			},
			error: function(jqXHR, textStatus, errorThrown) {
				alert(jqXHR.responseText);
			}
		});
	}
}
function onMobileValidation(e) {
	if (e.isValid) {
		var re = new RegExp("^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$");
		if (!re.test(e.value)) {
			e.errorText = "输入的手机号码格式有误";
			e.isValid = false;
		}
	}
}
function onRechargeAmountValidation(e) {
	if (e.isValid) {
		if (e.value < 10 || e.value > 1000) {
			e.errorText = "充值金额范围10-1000";
			e.isValid = false;
		}
	}
}

function CloseWindow(action) {
	if (action == "close" && form.isChanged()) {
		if (confirm("数据被修改了，是否先保存？")) {
			return false;
		}
	}
	if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
	else window.close();
}

function onOk(e) {
	SaveData();
}
function onCancel(e) {
	CloseWindow("cancel");
}